{% do load_script('review/list') %}
{% if member and canReview|default(1) %}
  <div class="clearfix">
    <button class="btn btn-primary btn-sm pull-right js-show-review-form" {% if not userReview %}style="display:none;"{% endif %}>{{'重新评价'|trans}}</button>
  </div>

  <form id="review-form" method="post" action="{{ reviewSaveUrl }}" {% if userReview %}style="display:none;"{% endif %}>
    <div class="form-group controls">
      {{'请打分：'|trans}} <span data-rating="{{ userReview.rating|default(0) }}" data-img-path="{{ app.request.basePath ~ '/assets/img/raty'}}" class="rating-btn"></span>
      <input type="hidden" name="rating" value="{{ userReview.rating|default(0) }}">
    </div>

    <div class="form-group controls">
      <textarea class="form-control" rows="8" data-display="{{'评价详细内容'|trans}}" name="content">{{ userReview.content|default('') }}</textarea>
    </div>

    <div class="form-group clearfix">
      <span class="text-success pull-left" style="display: none;">{{'评价已保存！'|trans}}</span>
      <a href="javascript:;" class="btn btn-primary pull-right js-btn-save" data-loading-text="{{'正在保存'|trans}}..." autocomplete="off">{{'保存'|trans}}</a>
      <a href="javascript:;" class="btn btn-link pull-right js-hide-review-form" {% if userReview %}style="display:none;"{% endif %}>{{'取消'|trans}}</a>
    </div>

    <input type="hidden" name="_csrf_token" value="{{ csrf_token('site') }}">
  </form>
{% endif %}

{% set canAccess = canAccess|default(false) %}

{% for review in reviews if users[review.userId]|default(false) %}
  {% set user = users[review.userId] %}
  {% set posts = data('ReviewPosts',{reviewId:review.id, targetType:targetType|default('course'), start:0,limit:5})|default(null) %}

  <div class="js-reviews">
    <div class="media media-evaluate">
      <div class="media-left">
        {{ web_macro.user_avatar(user, '', 'avatar-sm') }}
      </div>
      <div class="media-body thread-post">
        <div class="title">{{ web_macro.user_link(user) }} 
          {% if review.meta %}<span>{{'课程完成进度'|trans}}:{{ review.meta.learnedNum }}/{{ review.meta.lessonNum}}</span>{% endif %}&nbsp;&nbsp;
          {{ review.createdTime|date('Y-m-d') }} 
        </div>
        <div class="score">
          {{ web_macro.star(review.rating) }}
        </div>
        <div class="content">
          <div class="short-content">{{ review.content|sub_text(100) }}
            {% if review.updatedTime %}<span class="label label-success">{{'追评'|trans}}</span>{% endif %}
          </div>
          <div class="full-content" style="display:none;">{{ review.content|nl2br }}
            {% if review.updatedTime %}<span class="label label-success">{{'追评'|trans}}</span>{% endif %}
          </div>
        </div>
        <div class="actions clearfix">
          <a href="javascript:;" class="show-full-btn" style="display:none;">[{{'展开全文'|trans}}]</a>
          <a href="javascript:;" class="show-short-btn" style="display:none;">[{{'收起全文'|trans}}]</a>
          {% if canAccess %}
            <a href="javascript:;" class="js-reply pull-right">{% if posts is empty %}{{'回复'|trans}}{% else %}{{'收起'|trans}}{% endif %}</a>
          {% endif %}
        </div>
        
        {% set goto = goto|default(path('homepage')) %}
        {% if targetType|default('course') == 'classroom' %}
          {% set postReplyUrl = path('classroom_review_post',{id:review.classroomId,reviewId:review.id}) %}
        {% else %}
          {% set postReplyUrl = path('course_review_post',{id:review.courseId,reviewId:review.id}) %}
        {% endif %}

        <div class="thread-subpost-container subcomments clearfix {% if posts is empty %}hide{% endif %}">
          <div class="thread-subpost-content">
            {% include 'TopxiaWebBundle:Review/Widget:subposts.html.twig' with {posts:posts,targetType:targetType|default('course'),canAccess:canAccess|default(false)} %}
          </div>
          
          {% if canAccess %}
            <div class="thread-subpost-morebar clearfix {% if posts is empty %}hide{% endif %}">
              <button class="btn btn-default btn-xs pull-right js-toggle-subpost-form">{{'回复'|trans}}</button>
            </div>
          {% endif %}

          {% if app.user %}
            <form method="post" action="{{ postReplyUrl }}" class="thread-subpost-form {% if posts %}hide{% endif %}">
              <div class="form-group">
                <div class="controls">
                  <textarea class="form-control" name="content" data-display="{{'内容'|trans}}"></textarea>
                </div>
              </div>
              <div class="form-group">
                <input type="hidden" name="_csrf_token" value="{{ csrf_token('site') }}">
                <button type="submit" data-loading-text="{{'正在发表'|trans}}" class="btn btn-primary btn-sm pull-right">{{'发表'|trans}}</button>
              </div>
            </form>
          {% else %}
            <div class="empty">
              {{'你还没有登录，请先'|trans}}<a href="{{ path('login',{goto:goto}) }}">{{'登录'|trans}}</a>{{'或'|trans}}<a href="{{ path('register',{goto:goto}) }}">{{'注册'|trans}}</a>！
            </div>
          {% endif %}
        </div>

      </div>
    </div>
  </div>

{% else %}
  <div class="empty">{{'暂无评价'|trans}}</div>
{% endfor %}

{% if paginator|default(null) %}
  {{ web_macro.paginator(paginator) }}
{% endif  %}
